import { camelCase } from "../case"
import httpClient from "../httpclient"

export class DailyOrder {
  public date: string
  public totalCount: number
  public totalQuantity: number
  public totalPrice: number
  public totalAmount: number
}

export class MonthlyOrder {
  public yearMonth: string
  public month: string
  public totalCount: number
  public totalQuantity: number
  public totalPrice: number
  public totalAmount: number
}

export class TotalOrders {
  public totalCount: number
  public totalQuantity: number
  public totalPrice: number
  public totalAmount: number
}

export class OrderQuery {

  private params = {}

  public storeId(storeId: string): OrderQuery {
    this.params["store_id"] = storeId
    return this
  }

  public date(date: string | number): OrderQuery {
    this.params["date"] = date
    return this
  }

  public dateFrom(dateFrom: string | number): OrderQuery {
    this.params["date_from"] = dateFrom
    return this
  }

  public dateTo(dateTo: string | number): OrderQuery {
    this.params["date_to"] = dateTo
    return this
  }
}


export class OrderReportV1 {

  public static createOrderQuery() {
    return new OrderQuery()
  }

  public static queryDailyOrders(query: OrderQuery): Promise<DailyOrder[]> {
    return httpClient.get("/v1/reports/daily-orders", {
      params: query["params"],
    })
      .then(({ data }) => data)
      .then(camelCase)
  }

  public static queryMonthlyOrders(query: OrderQuery): Promise<MonthlyOrder[]> {
    return httpClient.get("/v1/reports/monthly-orders", {
      params: query["params"],
    })
      .then(({ data }) => data)
      .then(camelCase)
  }

  public static queryTotalOrders(query: OrderQuery): Promise<TotalOrders> {
    return httpClient.get("/v1/reports/total-orders", {
      params: query["params"],
    })
      .then(({ data }) => data)
      .then(camelCase)
  }
}
